<template>
  <!--个人中心-->
  <div class="wrapper wbgcolor">
    <div class="w1200 personal">
      <div class="credit-ad">
        <img src="~/assets/images/clist1.jpg" width="1200" height="96" />
      </div>
      <div class="personal-left">
        <InvestorNav v-if="userType === 1" />
        <BorrowerNav v-if="userType === 2" />
      </div>
      <NuxtChild />
      <div class="clear"></div>
    </div>
  </div>
</template>

<script>
import "~/assets/css/user.css";
import InvestorNav from "~/components/InvestorNav";
import BorrowerNav from "~/components/BorrowerNav";
import cookie from "js-cookie";

export default {
  components: {
    InvestorNav,
    BorrowerNav,
  },

  data() {
    return {
      userType: 0,
    };
  },

  mounted() {
    //因为appHeader需要发送异步请求查询srb-user然后设置到localStorage中
    //当前页面刷新时，appHeader和user.vue的mounted会同时执行，appheader的异步请求执行时间肯定要长
    //此处延迟执行，等待appheader执行结束再执行 就可以获取到localStorage中的缓存使用
    setTimeout(() => {
      let srbUser = localStorage.getItem("SRB-USER");
      if (srbUser) {
        //一定要把json字符串转为json对象(对象.属性)
        srbUser = JSON.parse(srbUser);
        this.userType = srbUser.userType;
      }
    }, 200);
  },
};
</script>
